package cn.smbms.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.smbms.pojo.User;

@RequestMapping("/index")
@Controller
public class IndexController {

	@RequestMapping(value = "/welcome0", method = RequestMethod.GET, params = "name")
	public String welcome0(String name) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		return "index";
	}

	@RequestMapping(value = "/welcome", method = RequestMethod.GET)
	public String welcome(String name) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		return "index";

	}

	@RequestMapping(value = "/welcome1", method = RequestMethod.GET)
	public ModelAndView welcome1(String name) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		ModelAndView mView = new ModelAndView();
		mView.addObject("name", name);
		mView.setViewName("index");
		return mView;

	}

	@RequestMapping(value = "/welcome2", method = RequestMethod.GET)
	public String welcome2(@RequestParam(value = "name", required = false) String name) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		return "index";
	}

	@RequestMapping(value = "/welcome3", method = RequestMethod.GET)
	public String welcome3(String name, Model model) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		model.addAttribute("name", name);
		model.addAttribute(name);
		User user = new User();
		user.setUserName(name);
		model.addAttribute("currentUser", user);
		model.addAttribute(user);
		return "index";
	}

	@RequestMapping(value = "/welcome4", method = RequestMethod.GET)
	public String welcome3(String name, Map<String, Object> map) {
		System.out.println("hello,SpringMVC!>>>>" + name);
		map.put("name", name);
		return "index";
	}

	@RequestMapping(value = "/index.html", method = RequestMethod.GET)
	public String welcome3() {
		System.out.println("hello,SpringMVC!>>>>/index.html");
		return "index";
	}

	@RequestMapping(value = "/test.html", method = RequestMethod.GET)
	public String test(String userCode, String password, Map<String, Object> map) {
		if ("admin".equals(userCode) && "admin".equals(password)) {
			System.out.println("hello,SpringMVC!>>>>" + userCode + ":>>>" + password);
			map.put("userCode", userCode);
			return "success";
		}
		return "index";
	}

}
